<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .goodsImg{width:200px;height:200px;}
    </style>
</head>
<body>
    <h2>这是商品详情页</h2>
    <img src="" class="goodsImg" alt="">
    <p>名称：<span class="name"></span></p>
    <p>原价：<span class="oldPrice"></span>，现价：<span class="newPrice"></span></p>
    <p>销量：<span class="sale"></span></p>
    <p>库存：<span class="stock"></span></p>
    <p>评分：<span class="score"></span></p>
</body>
<script src="./js/ajax.js"></script>
<script>

    // console.log(location.hash.slice(1))
    ajax({
        url:"http://localhost:3000/getgoods",
        data:{
            id: location.hash.slice(1)
        },
        success:(res)=>{
            res = JSON.parse(res).data[0];

            $(".goodsImg").src = res.goodsImg;
            $(".name").innerText = res.goodsName;
            $(".oldPrice").innerText = res.price;
            $(".newPrice").innerText = (res.price * res.discount * 0.1).toFixed(2);
            $(".sale").innerText = res.sale;
            $(".stock").innerText = res.stock;
            $(".score").innerText = res.score;
        }
    })

    function $(sel){
        return document.querySelector(sel)
    }


</script>
</html>